function trim(B) {
    var A = B.replace(/^\s*$/g, "");
    return A
}

function bindEvent(A, C, B) {
    if (!document.addEventListener) {
        A.attachEvent(C, B)
    } else {
        A.addEventListener(C, B, false)
    }
}

function delEvent(A, C, B) {
    if (!document.removeEventListener) {
        A.detachEvent(C, B)
    } else {
        A.removeEventListener(C, B, false)
    }
}

function addClass(B, D) {
    var A = new RegExp("\\b" + D + "\\b");
    if (B.length > 1) {
        for (var C = 0; C < B.length; C++) {
            if (!A.test(B[C].className)) {
                if (B[C].className) {
                    B[C].className += " " + D
                } else {
                    B[C].className = D
                }
            }
        }
    } else {
        if (!A.test(B.className)) {
            if (B.className) {
                B.className += " " + D
            } else {
                B.className = D
            }
        }
    }
    return B
}

function removeClass(B, D) {
    var A = new RegExp("\\b" + D + "\\b", "g");
    if (B.length > 1) {
        for (var C = 0; C < B.length; C++) {
            B[C].className = B[C].className.replace(A, "").replace(/\s+/g, " ")
        }
    } else {
        B.className = B.className.replace(A, "").replace(/\s+/g, " ")
    }
    return B
}

function createScript(A) {
    var B = document.getElementsByTagName("head")[0],
        C = document.createElement("script");
    C.src = A;
    C.charset = "utf-8";
    B.appendChild(C)
}

function _ajax(B, A, C) {
    var D = null;
    if (window.ActiveXObject) {
        D = new ActiveXObject("Microsoft.XMLHTTP")
    } else {
        D = new XMLHttpRequest()
    }
    D.onreadystatechange = function () {
        if ((D.status >= 200 && D.status < 300) || D.status == 304) {
            A(JSON.parse(D.responseText))
        } else {
            C()
        }
    };
    D.open("get", B, false);
    D.send(null)
}

function getWinWidth() {
    return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0
}

function getWinHeight() {
    return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0
}

function getWinScrollHeight() {
    return document.documentElement.scrollTop || document.body.scrollTop
}

function newsMore() {
    var B = document.querySelectorAll(".j_newsBtn");
    for (var A = 0; A < B.length; A++) {
        bindEvent(B[A], "click", function () {
            var E = this.parentNode.previousElementSibling || this.parentNode.previousSibling,
                F = this.nextElementSibling || this.nextSibling,
                C = E.querySelectorAll(".hide");
            for (var D = 0; D < C.length; D++) {
                removeClass(C[D], "hide")
            }
            removeClass(this, "show");
            addClass(this, "hide");
            removeClass(F, "hide");
            addClass(F, "show")
        })
    }
}

function picHeight() {
    var C = document.querySelectorAll(".j_newspic_dt"),
        F = document.querySelectorAll(".j_newspic_dd");
    var G = Math.ceil((getWinWidth() - 24 - 4) / 2),
        A = Math.floor(G * 3 / 4) - 5,
        B = document.querySelectorAll(".news_pic_items a"),
        E = document.querySelectorAll(".j_newspic_dd a");
    if (C && F) {
        for (var D = 0; D < C.length; D++) {
            C[D].style["height"] = F[D].offsetHeight - 4 + "px"
        }
        for (var D = 0; D < E.length; D++) {
            E[D].style["height"] = A + "px"
        }
    }
    for (var D = 0; D < B.length; D++) {
        B[D].style["height"] = A + "px"
    }
}

function scrollTop() {
    var C = document.querySelector(".gotop"),
        D = getWinHeight(),
        G = D * 1.5,
        A = getWinScrollHeight(),
        F, B = document.querySelectorAll(".news_module");

    function E() {
        var K = getCurIndex(),
            L = B[K] ? B[K].querySelectorAll("img") : [],
            H = B[K - 1] ? B[K - 1].querySelectorAll("img") : [],
            J = B[K + 1] ? B[K + 1].querySelectorAll("img") : [];
        if (L.length > 0) {
            for (var I = 0; I < L.length; I++) {
                if (L[I].getAttribute("data-src") && L[I].getAttribute("data-src") != L[I].src) {
                    L[I].src = L[I].getAttribute("data-src")
                }
            }
        }
        if (J.length > 0) {
            for (var I = 0; I < J.length; I++) {
                if (J[I].getAttribute("data-src") && J[I].getAttribute("data-src") != J[I].src) {
                    J[I].src = J[I].getAttribute("data-src")
                }
            }
        }
        if (H.length > 0) {
            for (var I = 0; I < H.length; I++) {
                if (H[I].getAttribute("data-src") && H[I].getAttribute("data-src") != H[I].src) {
                    H[I].src = H[I].getAttribute("data-src")
                }
            }
        }
        picHeight()
    }
    E();
    bindEvent(window, "scroll", function (H) {
        if (getWinScrollHeight() > G && getWinScrollHeight() < A) {
            addClass(C, "showbtn");
            if (F) {
                clearTimeout(F)
            }
            F = setTimeout(function () {
                removeClass(C, "showbtn")
            }, 3000)
        } else {
            removeClass(C, "showbtn")
        }
        E();
        A = getWinScrollHeight()
    });
    bindEvent(C, "click", function () {
        window.scrollTo(0, 0)
    })
}
var IRoller = function (A) {
    this.wrap = document.getElementById(A);
    this.rollItem = this.wrap.children;
    this.len = this.rollItem.length;
    this.currentNum = 0;
    this._height = this.wrap.offsetHeight;
    this.interval = 3000;
    this.timer = null;
    this.firstInit = true;
    if (this.wrap.children.length < 2) {
        return
    } else {
        if (this.wrap.children.length == 2) {
            this.wrap.appendChild(this.rollItem[0].cloneNode(true));
            this.wrap.appendChild(this.rollItem[1].cloneNode(true));
            this.rollItem = this.wrap.children;
            this.len = this.rollItem.length
        }
    }
    this.round = function (B) {
        if (this.currentNum + B < 0) {
            return this.currentNum + B + this.len
        } else {
            if (this.currentNum + B > this.len - 1) {
                return this.currentNum + B - this.len
            } else {
                return this.currentNum + B
            }
        }
    };
    this.translate = function (C, E, B) {
        var F = navigator.userAgent.toLowerCase(),
            D = C && C.style;
        D.webkitTransitionDuration = D.MozTransitionDuration = D.msTransitionDuration = D.OTransitionDuration = D.transitionDuration = B + "ms";
        D.webkitTransitionTimingFunction = D.MozTransitionTimingFunction = D.msTransitionTimingFunction = D.OTransitionTimingFunction = D.transitionTimingFunction = "ease-in-out";
        if (F.indexOf("gt-") != -1) {
            D.webkitTransform = "translateY(" + E + "px)"
        } else {
            D.webkitTransform = "translate3d(0, " + E + "px, 0)"
        }
        D.msTransform = D.MozTransform = D.OTransform = "translateY(" + E + "px)"
    };
    this.setAnimation = function () {
        var B = this;
        for (var C = 0; C < B.len; C++) {
            if (C == B.round(-1)) {
                if (B.firstInit) {
                    B.translate(B.rollItem[C], -B._height, 0)
                } else {
                    B.translate(B.rollItem[C], -B._height, 1000)
                }
                B.rollItem[C].style["z-index"] = 5
            } else {
                if (C == B.round(1)) {
                    if (B.firstInit) {
                        B.translate(B.rollItem[C], B._height, 0)
                    } else {
                        B.translate(B.rollItem[C], B._height, 1000)
                    }
                    B.rollItem[C].style["z-index"] = 5
                } else {
                    if (C == B.currentNum) {
                        if (B.firstInit) {
                            B.translate(B.rollItem[C], 0, 0)
                        } else {
                            B.translate(B.rollItem[C], 0, 1000)
                        }
                        B.rollItem[C].style["z-index"] = 5
                    } else {
                        B.translate(B.rollItem[C], B._height, 0);
                        B.rollItem[C].style["z-index"] = 1
                    }
                }
            }
        }
    };
    this.init = function () {
        var B = this;
        B.setAnimation();
        B.timer = setInterval(function () {
            B.currentNum = B.round(1);
            B.firstInit = false;
            B.setAnimation()
        }, B.interval)
    };
    this.init()
};
var Swiper = function (C, A, B) {
    this.wrap = C;
    this.tabs = A ? A.children : null;
    this.currentNum = B.startIndex || 0;
    this.auto = B.auto && true;
    this.interval = B.interval || 3000;
    this.speed = B.speed || 300;
    this.maxHeight = B.maxHeight || Infinity;
    this.callback = B.callback || null;
    this.circular = B.circular || false;
    this.innerWrap = this.wrap.children[0];
    this.items = this.innerWrap.children;
    this.len = this.items.length;
    if (this.len == 0) {
        return
    } else {
        if (this.len == 1) {
            this.wrap.style["height"] = this.items[0].offsetHeight;
            this.wrap.style["width"] = this.items[0].offsetWidth;
            return
        } else {
            if (this.len == 2 && this.circular) {
                this.innerWrap.appendChild(this.items[0].cloneNode(true));
                this.innerWrap.appendChild(this.items[1].cloneNode(true));
                this.len = 4
            }
        }
    }
    this._width = 0;
    this._height = 0;
    this.X = 0;
    this.curX = 0;
    this.Y = 0;
    this.curY = 0;
    this.direction = 0;
    this.eventInit = false;
    this.firstInit = false;
    this.slideTimer = null;
    this.timerCleared = false;
    this.isScrolling = false;
    this.isValidSlide = false;
    this.init()
};
Swiper.prototype = {
    init: function () {
        var A = this;
        A.wrap.style["position"] = "relative";
        A.innerWrap.style["position"] = "relative";
        A._width = A.wrap.getBoundingClientRect().width || A.wrap.offsetWidth;
        A._height = Math.min(A.items[A.currentNum].getBoundingClientRect().height || A.items[A.currentNum].offsetHeight, A.maxHeight);
        A.innerWrap.style["width"] = A._width + "px";
        A.innerWrap.style["height"] = A._height + "px";
        for (var B = 0; B < A.len; B++) {
            A.items[B].style["position"] = "absolute";
            A.items[B].style["left"] = "0";
            A.items[B].style["top"] = "0"
        }
        A.firstInit = true;
        A.gotoPage(A.currentNum);
        if (!A.eventInit) {
            A.addEvent();
            A.eventInit = true
        }
        if (A.auto && !A.timerCleared) {
            A._stop();
            A.slideTimer = setInterval(function () {
                A.gotoPage(A.round(1))
            }, A.interval);
            A.timerCleared = false
        }
    },
    touchX: function (A) {
        if (A.touches) {
            return A.touches[0].pageX
        } else {
            return A.pageX
        }
    },
    touchY: function (A) {
        if (A.touches) {
            return A.touches[0].pageY
        } else {
            return A.pageY
        }
    },
    setAnimation: function () {
        var H = this.items,
            B = this.tabs,
            A = this.len,
            D = this.speed,
            C = this._width,
            I = this.round(1),
            G = this.round(-1),
            F = this.currentNum;
        for (var E = 0; E < A; E++) {
            if (this.circular) {
                if (E == I) {
                    if (!this.firstInit && !this.timerCleared) {
                        this.translate(H[E], C, D)
                    } else {
                        this.translate(H[E], C, 0)
                    }
                    H[E].style["display"] = "block"
                } else {
                    if (E == G) {
                        if (!this.firstInit && !this.timerCleared) {
                            this.translate(H[E], -C, D)
                        } else {
                            this.translate(H[E], -C, 0)
                        }
                        H[E].style["display"] = "block"
                    } else {
                        if (E == F) {
                            if (!this.firstInit && !this.timerCleared) {
                                this.translate(H[E], 0, D)
                            } else {
                                this.translate(H[E], 0, 0)
                            }
                            H[E].style["display"] = "block"
                        } else {
                            H[E].style["display"] = "none";
                            this.translate(H[E], -C, D)
                        }
                    }
                }
            } else {
                if (!this.firstInit) {
                    this.translate(H[E], (E - F) * C, D)
                } else {
                    this.translate(H[E], (E - F) * C, 0)
                }
                H[E].style["display"] = "block"
            }
        }
        this.firstInit = false;
        if (this.maxHeight === Infinity) {
            this.innerWrap.style["height"] = this.items[F].offsetHeight + "px"
        }
    },
    translate: function (B, D, A) {
        var E = navigator.userAgent.toLowerCase(),
            C = B && B.style;
        C.webkitTransitionDuration = C.MozTransitionDuration = C.msTransitionDuration = C.OTransitionDuration = C.transitionDuration = A + "ms";
        C.webkitTransitionTimingFunction = C.MozTransitionTimingFunction = C.msTransitionTimingFunction = C.OTransitionTimingFunction = C.transitionTimingFunction = "ease-in-out";
        if (E.indexOf("gt-") != -1) {
            C.webkitTransform = "translateX(" + D + "px)"
        } else {
            C.webkitTransform = "translate3d(" + D + "px, 0, 0)"
        }
        C.msTransform = C.MozTransform = C.OTransform = "translateX(" + D + "px)"
    },
    switchTab: function () {
        var C = this.tabs,
            B = C ? this.currentNum % C.length : undefined;
        if (C && C.length > 0) {
            for (var A = 0; A < C.length; A++) {
                if (A == B) {
                    addClass(C[B], "on")
                } else {
                    removeClass(C[A], "on")
                }
            }
        }
    },
    slide: function (E) {
        var A = this,
            F = A._width,
            B = A.currentNum,
            D = A.items,
            C = A.round(1),
            G = A.round(-1);
        if ((!this.circular && C != -1 && G != -1) || this.circular) {
            this.translate(D[B], E, 0);
            this.translate(D[C], F + E, 0);
            this.translate(D[G], -F + E, 0)
        }
    },
    round: function (A) {
        if (this.circular) {
            if (this.currentNum + A < 0) {
                return this.currentNum + A + this.len
            } else {
                if (this.currentNum + A > this.len - 1) {
                    return this.currentNum + A - this.len
                } else {
                    return this.currentNum + A
                }
            }
        } else {
            if (this.currentNum + A < 0 || this.currentNum + A > this.len - 1) {
                return -1
            } else {
                return this.currentNum + A
            }
        }
    },
    addEvent: function () {
        var C = this.innerWrap,
            D = this.tabs,
            A = this;
        bindEvent(C, "touchstart", function (E) {
            A._touchstart(E)
        });
        bindEvent(C, "touchmove", function (E) {
            A._touchmove(E)
        });
        bindEvent(C, "touchend", function (E) {
            A._touchend(E)
        });
        bindEvent(window, "resize", function () {
            A.init()
        });
        if (D && D.length > 0) {
            for (var B = 0; B < D.length; B++) {
                D[B].index = B;
                bindEvent(D[B], "click", function () {
                    A.gotoPage(this.index)
                })
            }
        }
    },
    _stop: function () {
        if (!this.timerCleared) {
            clearInterval(this.slideTimer);
            this.timerCleared = true
        }
    },
    _touchstart: function (A) {
        this.X = this.touchX(A);
        this.Y = this.touchY(A);
        this.isScrolling = undefined
    },
    _touchmove: function (B) {
        var A = this,
            D, C;
        A.curX = A.touchX(B);
        A.curY = A.touchY(B);
        D = A.curX - A.X;
        C = A.curY - A.Y;
        if (typeof A.isScrolling == "undefined") {
            A.isScrolling = !!(A.isScrolling || Math.abs(D) < Math.abs(C))
        }
        if (!A.isScrolling) {
            B.preventDefault();
            A._stop();
            A.slide(D)
        }
    },
    _touchend: function (B) {
        var A = this,
            F = A.innerWrap,
            E = 0,
            D = 0;
        if (A.curX == 0) {
            A.curX = A.X
        }
        if (A.curY == 0) {
            A.curY = A.Y
        }
        E = A.curX - A.X;
        D = A.curY - A.Y;
        A.curX = 0;
        A.curY = 0;
        if (Math.abs(E) > Math.abs(D)) {
            if (Math.abs(E) > 30) {
                A.isValidSlide = true;
                A.direction = E > 0 ? 1 : 0
            } else {
                A.isValidSlide = false
            }
            if (A.isValidSlide) {
                var C = A.direction == 1 ? A.round(-1) : A.round(1);
                A.gotoPage(C)
            } else {
                A.setAnimation()
            }
        }
        delEvent(F, "touchstart", function (G) {
            A._touchstart(G)
        });
        delEvent(F, "touchmove", function (G) {
            A._touchmove(G)
        })
    },
    gotoPage: function (A) {
        if (A != -1) {
            this.currentNum = A;
            this.setAnimation();
            this.switchTab();
            this.callback(this.items[A], A, this.direction)
        }
    },
    kill: function () {
        var A = this,
            C = A.wrap,
            D = A.tabs;
        this._stop();
        var F = this.len;
        while (F--) {
            var E = this.items[F];
            E.style["-webkit-transition-duration"] = "0s";
            E.style["display"] = "block";
            E.style["-webkit-transform"] = "translate3d(0, 0, 0)"
        }
        delEvent(C, "touchstart", function (G) {
            A._touchstart(G)
        });
        delEvent(C, "touchmove", function (G) {
            A._touchmove(G)
        });
        delEvent(C, "touchend", function (G) {
            A._touchend(G)
        });
        delEvent(window, "resize", function () {
            A.init()
        });
        if (D && D.length > 0) {
            for (var B = 0; B < D.length; B++) {
                D[B].index = B;
                delEvent(D[B], "click", function () {
                    A.gotoPage(this.index)
                })
            }
        }
    }
};
var IScroller = function (A) {
    this.wrap = document.getElementById(A);
    this.parentW = 0;
    this.scrollItem = this.wrap.children;
    this.len = this.scrollItem.length;
    this._width = this.scrollItem[0].offsetWidth;
    this._height = this.scrollItem[0].offsetHeight;
    this.actualW = this._width * this.len;
    this.currentPos = 0;
    this.X = 0;
    this.curX = 0;
    this.Y = 0;
    this.curY = 0;
    this.isScrolling = false;
    this.init()
};
IScroller.prototype = {
    init: function () {
        var A = this;
        this.parentW = this.wrap.offsetWidth;
        A.wrap.style["width"] = A.actualW + "px";
        A.wrap.style["height"] = A._height + "px";
        if (A.actualW > A.parentW) {
            A.addEvent()
        } else {
            this.currentPos = 0
        }
        A.setAnimation()
    },
    touchX: function (A) {
        if (A.touches) {
            return A.touches[0].pageX
        } else {
            return A.pageX
        }
    },
    touchY: function (A) {
        if (A.touches) {
            return A.touches[0].pageY
        } else {
            return A.pageY
        }
    },
    setAnimation: function () {
        var A = this,
            B = A.wrap;
        B.style["-webkit-transition"] = "-webkit-transform 0.3s ease-in-out";
        B.style["-webkit-transform"] = "translate3d(" + A.currentPos + "px, 0, 0)"
    },
    slide: function (C) {
        var A = this,
            B = A.wrap;
        B.style["-webkit-transition-duration"] = "0s";
        B.style["-webkit-transform"] = "translate3d(" + (A.currentPos + C) + "px, 0, 0)"
    },
    addEvent: function () {
        var B = this.wrap,
            A = this;
        bindEvent(B, "touchstart", function (C) {
            A._touchstart(C)
        });
        bindEvent(B, "touchmove", function (C) {
            A._touchmove(C)
        });
        bindEvent(B, "touchend", function (C) {
            A._touchend(C)
        })
    },
    _touchstart: function (A) {
        this.X = this.touchX(A);
        this.Y = this.touchY(A);
        this.isScrolling = undefined
    },
    _touchmove: function (B) {
        var A = this,
            D, C;
        A.curX = A.touchX(B);
        A.curY = A.touchY(B);
        D = A.curX - A.X;
        C = A.curY - A.Y;
        if (typeof A.isScrolling == "undefined") {
            A.isScrolling = !!(A.isScrolling || Math.abs(D) < Math.abs(C))
        }
        if (!A.isScrolling) {
            B.preventDefault();
            A.slide(D)
        }
    },
    _touchend: function (B) {
        var A = this,
            E = A.wrap,
            D = 0,
            C = 0;
        if (A.curX == 0) {
            A.curX = A.X
        }
        if (A.curY == 0) {
            A.curY = A.Y
        }
        D = A.curX - A.X;
        C = A.curY - A.Y;
        A.curX = 0;
        A.curY = 0;
        if (Math.abs(D) > Math.abs(C)) {
            if (A.currentPos + D > 0) {
                A.currentPos = 0
            } else {
                A.currentPos = Math.max(A.currentPos + D, A.parentW - A.actualW)
            }
            A.setAnimation()
        }
        delEvent(E, "touchstart", function (F) {
            A._touchstart(F)
        });
        delEvent(E, "touchmove", function (F) {
            A._touchmove(F)
        })
    }
};

function rollInit() {
    var C = document.querySelectorAll(".j_roll");
    for (var A = 0; A < C.length; A++) {
        C[A].id = "iRoll" + A;
        var B = new IRoller("iRoll" + A)
    }
}

function slideStyleInit() {
    var B = document.querySelector(".j_imgSlide"),
        C = B.children[0],
        A = Math.ceil(getWinWidth() / 2);
    B.style["height"] = A + "px";
    C.style["height"] = A + "px"
}

function tabInit(B, C) {
    if (B.length > 0 && B.length === C.length) {
        for (var A = 0; A < B.length; A++) {
            B[A].index = A;
            if (A == 0) {
                addClass(B[A], "on");
                removeClass(C[A], "hide")
            } else {
                removeClass(B[A], "on");
                addClass(C[A], "hide")
            }
            bindEvent(B[A], "click", function () {
                var E = this.parentNode.children;
                for (var D = 0; D < E.length; D++) {
                    if (D == this.index) {
                        addClass(E[D], "on");
                        removeClass(C[D], "hide")
                    } else {
                        removeClass(E[D], "on");
                        addClass(C[D], "hide")
                    }
                }
            })
        }
    }
}

function moduleInit() {
    var A = document.querySelectorAll(".j_newsModule"),
        C = document.querySelectorAll(".j_navTab");
    for (var B = 0; B < A.length; B++) {
        tabInit(C[B].children, A[B].children[0].children)
    }
}

function iScrollInit() {
    var B = document.querySelectorAll(".j_scroll");
    for (var A = 0; A < B.length; A++) {
        B[A].id = "iScroll" + A;
        var C = new IScroller("iScroll" + A)
    }
}

function getCurIndex() {
    var C = document.querySelectorAll(".news_module"),
        A = document.querySelectorAll(".j_newsModule")[0].offsetTop;
    for (var B = 0; B < C.length; B++) {
        if (C[B].getBoundingClientRect().top <= 0 && C[B].getBoundingClientRect().bottom >= 87 && getWinScrollHeight() > A) {
            return B
        }
    }
    return -1
}

function tabNav() {
    var D = document.querySelectorAll(".j_navTab"),
        B = document.querySelectorAll(".j_newsModule"),
        E = document.querySelector(".news_tab_fixed"),
        C = document.querySelectorAll(".news_module");

    function A() {
        var H = getCurIndex();
        if (H !== -1) {
            addClass(E, "fixed_show");
            E.innerHTML = D[H].innerHTML;
            var I = D[H].getAttribute("data-sudaclick");
            if (I) {
                E.setAttribute("data-sudaclick", I)
            } else {
                E.removeAttribute("data-sudaclick")
            }
            var G = E.children;
            for (var F = 0; F < G.length; F++) {
                G[F].index = F;
                G[F].tab = D[H].children[F];
                G[F].item = B[H].children[0].children[F];
                bindEvent(G[F], "click", function () {
                    var M = this.parentNode.children,
                        L = this.tab,
                        J = L.parentNode.children;
                    item = this.item, items = item.parentNode.children;
                    for (var K = 0; K < M.length; K++) {
                        if (K == this.index) {
                            addClass(M[K], "on");
                            addClass(J[K], "on");
                            removeClass(items[K], "hide")
                        } else {
                            removeClass(M[K], "on");
                            removeClass(J[K], "on");
                            addClass(items[K], "hide")
                        }
                    }
                    window.scrollTo(0, C[H].offsetTop)
                })
            }
        } else {
            removeClass(E, "fixed_show")
        }
    }
    A();
    bindEvent(window, "scroll", function () {
        A()
    })
}
setTimeout(function () {
    rollInit();
    //slideStyleInit();
    moduleInit();
    iScrollInit();
    tabNav();
    scrollTop();
//    window.addEventListener("resize", function () {
//        picHeight();
//        slideStyleInit()
//    })
}, 300);